import os
import sys

# 请在此输入您的代码

n, m = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(n)]

#8 dirrections
dirs = [(-1,0),(-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


ans = [[0] * m] * n

for i in range(n):
  for j in range(m):
    if a[i][j] == 1:
        ans[i][j] = 9
    else:
        ans[i][j] = 0
        for delta_x, delta_y in dirs:
            x = i + delta_x
            y = j + delta_y
            if 0<= x < n and 0 <= y < m:
                ans[i][j] += a[x][y]

    print(ans[i][j], end = ' ')
  print()



